//幕布
import { Vector3, Spherical } from "../three.module.js";

const defaAttr = () => ({
    lenT: 10,
    lenB: 1,
    lenA: 2,
    is1: false,
});

export default class Backdrop {
    constructor(attr) {
        Object.assign(this, defaAttr(), attr)

        this.normals = [];//顶点法向
        this.vertices = [];//顶点信息
        this.elements = [];//默认的Elements
        this.count = 0;


        if (this.is1) {
            this._init1();
        } else {
            this._init();
        }
    }

    _init() {
        const { normals, vertices, elements,
            lenT, lenB, lenA } = this;
        //   4-----5
        //   |  \  |
        //   0-----3
        //    \  \  \
        //     1-----2
        vertices.push(
            -lenT, -lenB, -lenA,
            -lenT, -lenB, lenT,
            lenT, -lenB, lenT,
            lenT, -lenB, -lenA,
            -lenT, lenT, -lenA,
            lenT, lenT, -lenA,
        );
        elements.push(
            0, 1, 2, 0, 2, 3,
            4, 0, 3, 4, 3, 5,
        );
        normals.push(
            0, 1, 1,
            0, 1, 0,
            0, 1, 0,
            0, 1, 1,
            0, 0, 1,
            0, 0, 1,
        );
    }

    _init1() {
        const { normals, vertices, elements,
            lenT, lenB, lenA } = this;
        //   4-----5
        //   |  \  |
        //   6-----7
        //   0-----3
        //    \  \  \
        //     1-----2
        vertices.push(
            -lenT, -lenB, -lenA,
            -lenT, -lenB, lenT,
            lenT, -lenB, lenT,
            lenT, -lenB, -lenA,
            -lenT, lenT, -lenA,
            lenT, lenT, -lenA,
            -lenT, -lenB, -lenA,
            lenT, -lenB, -lenA,
        );
        elements.push(
            0, 1, 2, 0, 2, 3,
            4, 6, 7, 4, 7, 5,
        );
        normals.push(
            0, 1, 0,
            0, 1, 0,
            0, 1, 0,
            0, 1, 0,
            0, 0, 1,
            0, 0, 1,
            0, 0, 1,
            0, 0, 1,
        );
    }
}